package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.ParkOrderModel;
import com.pengcheng.taskapplication.model.WashOrderModel;
import com.pengcheng.taskapplication.mvp.view.widget.CircleImageView;
import com.pengcheng.taskapplication.net.ConvertUtil;

import java.text.DecimalFormat;
import java.util.List;

public class ParkAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<ParkOrderModel> parkOrderModels;
	int last_item;
	private int selectedPosition = -1;
	public ParkAdapter(Context context, List<ParkOrderModel> parkOrderModels){
		this.context = context;
		this.parkOrderModels = parkOrderModels;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return parkOrderModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return parkOrderModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_park_item_layout, null);
			holder = new ViewHolder();
			holder.tv_order=(TextView) convertView.findViewById(R.id.tv_order);
			holder.tv_order_status=(TextView)convertView.findViewById(R.id.tv_order_status);
			holder.tv_order_pay_type=(TextView)convertView.findViewById(R.id.tv_order_pay_type);
			holder.tv_car_num=(TextView)convertView.findViewById(R.id.tv_car_num);
			holder.tv_park_time=(TextView)convertView.findViewById(R.id.tv_park_time);
			holder.tv_total_fee=(TextView)convertView.findViewById(R.id.tv_total_fee);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		ParkOrderModel model= parkOrderModels.get(position);
		holder.tv_order.setText(model.getCarnumber());

//		if(model.getStatus()==0){
//			holder.tv_order_status.setVisibility(View.VISIBLE);
//			holder.tv_order_pay_type.setVisibility(View.GONE);
//			holder.tv_order_status.setText("未支付");
//		}else{
			holder.tv_order_status.setVisibility(View.GONE);
			holder.tv_order_pay_type.setVisibility(View.VISIBLE);
			switch (model.getPayway()){
				case 2:
					holder.tv_order_pay_type.setText("微信支付");
					break;
				case 3:
					holder.tv_order_pay_type.setText("支付宝支付");
					break;
				case 4:
					holder.tv_order_pay_type.setText("银行卡支付");
					break;
//			}

		}




		holder.tv_car_num.setText(model.getCarnumber());
		holder.tv_park_time.setText(""+ ConvertUtil.getInterval(model.getExittime(),model.getIntime()));
		DecimalFormat df = new DecimalFormat("#.00");
		holder.tv_total_fee.setText("￥"+df.format(model.getCostmoney()/100));
		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_order;
		public TextView tv_order_status;
		public TextView tv_order_pay_type;
		public TextView tv_car_num;
		public TextView tv_park_time;
		public TextView tv_total_fee;
		public CircleImageView circleImage;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

	public interface  OnStopLisener{
		void onStop(ParkOrderModel parkOrderModel);
	}
	private OnStopLisener  onStopLisner;

	public void setOnStopLisner(OnStopLisener onStopLisner) {
		this.onStopLisner = onStopLisner;
	}
}
